{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import shutil\n",
    "import cv2 as cv\n",
    "import numpy as np\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "os.chdir(\"/home/kiprono/Documents/STELLENBOSCH UNIVERISTY/\\\n",
    "Masters by Research/Mask RCNN/Annotation projects/RRR/images\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_images = os.listdir(os.getcwd())\n",
    "all_images;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RESIZING"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 ../resized/rr-0001-0003-1-62-0062.jpg\n",
      "2 ../resized/rr-0002-0003-1-62-0062.jpg\n",
      "3 ../resized/rr-0003-0003-1-62-0062.jpg\n",
      "4 ../resized/rr-0004-0003-1-62-0062.jpg\n",
      "1 ../resized/rr-0001-0005-11645-126-177.jpg\n",
      "2 ../resized/rr-0002-0005-11645-126-177.jpg\n",
      "3 ../resized/rr-0003-0005-11645-126-177.jpg\n",
      "4 ../resized/rr-0004-0005-11645-126-177.jpg\n",
      "1 ../resized/rr-0001-0005-11646-140-81.jpg\n",
      "2 ../resized/rr-0002-0005-11646-140-81.jpg\n",
      "3 ../resized/rr-0003-0005-11646-140-81.jpg\n",
      "4 ../resized/rr-0004-0005-11646-140-81.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0003-11447-75-92.jpg\n",
      "1 ../resized/rr-0001-0003-11447-75-92.jpg\n",
      "../resized/rr-0002-0003-11447-75-92.jpg\n",
      "2 ../resized/rr-0002-0003-11447-75-92.jpg\n",
      "../resized/rr-0003-0003-11447-75-92.jpg\n",
      "3 ../resized/rr-0003-0003-11447-75-92.jpg\n",
      "../resized/rr-0004-0003-11447-75-92.jpg\n",
      "4 ../resized/rr-0004-0003-11447-75-92.jpg\n",
      "1 ../resized/rr-0001-0002-12382-467-143.jpg\n",
      "2 ../resized/rr-0002-0002-12382-467-143.jpg\n",
      "3 ../resized/rr-0003-0002-12382-467-143.jpg\n",
      "4 ../resized/rr-0004-0002-12382-467-143.jpg\n",
      "1 ../resized/rr-0001-0006-12014-254-327.jpg\n",
      "2 ../resized/rr-0002-0006-12014-254-327.jpg\n",
      "3 ../resized/rr-0003-0006-12014-254-327.jpg\n",
      "4 ../resized/rr-0004-0006-12014-254-327.jpg\n",
      "1 ../resized/rr-0001-0004-11645-117-69.jpg\n",
      "2 ../resized/rr-0002-0004-11645-117-69.jpg\n",
      "3 ../resized/rr-0003-0004-11645-117-69.jpg\n",
      "4 ../resized/rr-0004-0004-11645-117-69.jpg\n",
      "1 ../resized/rr-0001-0001-11647-166-51.jpg\n",
      "2 ../resized/rr-0002-0001-11647-166-51.jpg\n",
      "3 ../resized/rr-0003-0001-11647-166-51.jpg\n",
      "4 ../resized/rr-0004-0001-11647-166-51.jpg\n",
      "1 ../resized/rr-0001-0002-11645-134-120.jpg\n",
      "2 ../resized/rr-0002-0002-11645-134-120.jpg\n",
      "3 ../resized/rr-0003-0002-11645-134-120.jpg\n",
      "4 ../resized/rr-0004-0002-11645-134-120.jpg\n",
      "1 ../resized/rr-0001-0005-1-92-0092.jpg\n",
      "2 ../resized/rr-0002-0005-1-92-0092.jpg\n",
      "3 ../resized/rr-0003-0005-1-92-0092.jpg\n",
      "4 ../resized/rr-0004-0005-1-92-0092.jpg\n",
      "1 ../resized/rr-0001-0002-12403-533-77.jpg\n",
      "2 ../resized/rr-0002-0002-12403-533-77.jpg\n",
      "3 ../resized/rr-0003-0002-12403-533-77.jpg\n",
      "4 ../resized/rr-0004-0002-12403-533-77.jpg\n",
      "1 ../resized/rr-0001-0005-12384-483-145.jpg\n",
      "2 ../resized/rr-0002-0005-12384-483-145.jpg\n",
      "3 ../resized/rr-0003-0005-12384-483-145.jpg\n",
      "4 ../resized/rr-0004-0005-12384-483-145.jpg\n",
      "1 ../resized/rr-0001-0002-1-128-0128.jpg\n",
      "2 ../resized/rr-0002-0002-1-128-0128.jpg\n",
      "3 ../resized/rr-0003-0002-1-128-0128.jpg\n",
      "4 ../resized/rr-0004-0002-1-128-0128.jpg\n",
      "1 ../resized/rr-0001-0003-2-55-0055.jpg\n",
      "2 ../resized/rr-0002-0003-2-55-0055.jpg\n",
      "3 ../resized/rr-0003-0003-2-55-0055.jpg\n",
      "4 ../resized/rr-0004-0003-2-55-0055.jpg\n",
      "1 ../resized/rr-0001-0001-1-49-0049.jpg\n",
      "2 ../resized/rr-0002-0001-1-49-0049.jpg\n",
      "3 ../resized/rr-0003-0001-1-49-0049.jpg\n",
      "4 ../resized/rr-0004-0001-1-49-0049.jpg\n",
      "1 ../resized/rr-0001-0005-1-187-0187.jpg\n",
      "2 ../resized/rr-0002-0005-1-187-0187.jpg\n",
      "3 ../resized/rr-0003-0005-1-187-0187.jpg\n",
      "4 ../resized/rr-0004-0005-1-187-0187.jpg\n",
      "1 ../resized/rr-0001-0004-2-82-0082.jpg\n",
      "2 ../resized/rr-0002-0004-2-82-0082.jpg\n",
      "3 ../resized/rr-0003-0004-2-82-0082.jpg\n",
      "4 ../resized/rr-0004-0004-2-82-0082.jpg\n",
      "1 ../resized/rr-0001-0003-12013-251-409.jpg\n",
      "2 ../resized/rr-0002-0003-12013-251-409.jpg\n",
      "3 ../resized/rr-0003-0003-12013-251-409.jpg\n",
      "4 ../resized/rr-0004-0003-12013-251-409.jpg\n",
      "1 ../resized/rr-0001-0002-11645-126-133.jpg\n",
      "2 ../resized/rr-0002-0002-11645-126-133.jpg\n",
      "3 ../resized/rr-0003-0002-11645-126-133.jpg\n",
      "4 ../resized/rr-0004-0002-11645-126-133.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0004-11444-28-95.jpg\n",
      "1 ../resized/rr-0001-0004-11444-28-95.jpg\n",
      "../resized/rr-0002-0004-11444-28-95.jpg\n",
      "2 ../resized/rr-0002-0004-11444-28-95.jpg\n",
      "../resized/rr-0003-0004-11444-28-95.jpg\n",
      "3 ../resized/rr-0003-0004-11444-28-95.jpg\n",
      "../resized/rr-0004-0004-11444-28-95.jpg\n",
      "4 ../resized/rr-0004-0004-11444-28-95.jpg\n",
      "1 ../resized/rr-0001-0005-1-49-0049.jpg\n",
      "2 ../resized/rr-0002-0005-1-49-0049.jpg\n",
      "3 ../resized/rr-0003-0005-1-49-0049.jpg\n",
      "4 ../resized/rr-0004-0005-1-49-0049.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0005-11446-44-84.jpg\n",
      "1 ../resized/rr-0001-0005-11446-44-84.jpg\n",
      "../resized/rr-0002-0005-11446-44-84.jpg\n",
      "2 ../resized/rr-0002-0005-11446-44-84.jpg\n",
      "../resized/rr-0003-0005-11446-44-84.jpg\n",
      "3 ../resized/rr-0003-0005-11446-44-84.jpg\n",
      "../resized/rr-0004-0005-11446-44-84.jpg\n",
      "4 ../resized/rr-0004-0005-11446-44-84.jpg\n",
      "1 ../resized/rr-0001-0004-12013-251-409.jpg\n",
      "2 ../resized/rr-0002-0004-12013-251-409.jpg\n",
      "3 ../resized/rr-0003-0004-12013-251-409.jpg\n",
      "4 ../resized/rr-0004-0004-12013-251-409.jpg\n",
      "1 ../resized/rr-0001-0004-1-25-0025.jpg\n",
      "2 ../resized/rr-0002-0004-1-25-0025.jpg\n",
      "3 ../resized/rr-0003-0004-1-25-0025.jpg\n",
      "4 ../resized/rr-0004-0004-1-25-0025.jpg\n",
      "1 ../resized/rr-0001-0004-1-49-0049.jpg\n",
      "2 ../resized/rr-0002-0004-1-49-0049.jpg\n",
      "3 ../resized/rr-0003-0004-1-49-0049.jpg\n",
      "4 ../resized/rr-0004-0004-1-49-0049.jpg\n",
      "1 ../resized/rr-0001-0005-1-62-0062.jpg\n",
      "2 ../resized/rr-0002-0005-1-62-0062.jpg\n",
      "3 ../resized/rr-0003-0005-1-62-0062.jpg\n",
      "4 ../resized/rr-0004-0005-1-62-0062.jpg\n",
      "1 ../resized/rr-0001-0001-1-119-0119.jpg\n",
      "2 ../resized/rr-0002-0001-1-119-0119.jpg\n",
      "3 ../resized/rr-0003-0001-1-119-0119.jpg\n",
      "4 ../resized/rr-0004-0001-1-119-0119.jpg\n",
      "1 ../resized/rr-0001-0004-11645-133-90.jpg\n",
      "2 ../resized/rr-0002-0004-11645-133-90.jpg\n",
      "3 ../resized/rr-0003-0004-11645-133-90.jpg\n",
      "4 ../resized/rr-0004-0004-11645-133-90.jpg\n",
      "1 ../resized/rr-0001-0003-12402-532-81.jpg\n",
      "2 ../resized/rr-0002-0003-12402-532-81.jpg\n",
      "3 ../resized/rr-0003-0003-12402-532-81.jpg\n",
      "4 ../resized/rr-0004-0003-12402-532-81.jpg\n",
      "1 ../resized/rr-0001-0003-11646-140-81.jpg\n",
      "2 ../resized/rr-0002-0003-11646-140-81.jpg\n",
      "3 ../resized/rr-0003-0003-11646-140-81.jpg\n",
      "4 ../resized/rr-0004-0003-11646-140-81.jpg\n",
      "1 ../resized/rr-0001-0002-2-82-0082.jpg\n",
      "2 ../resized/rr-0002-0002-2-82-0082.jpg\n",
      "3 ../resized/rr-0003-0002-2-82-0082.jpg\n",
      "4 ../resized/rr-0004-0002-2-82-0082.jpg\n",
      "1 ../resized/rr-0001-0002-12402-531-78.jpg\n",
      "2 ../resized/rr-0002-0002-12402-531-78.jpg\n",
      "3 ../resized/rr-0003-0002-12402-531-78.jpg\n",
      "4 ../resized/rr-0004-0002-12402-531-78.jpg\n",
      "1 ../resized/rr-0001-0004-12014-272-396.jpg\n",
      "2 ../resized/rr-0002-0004-12014-272-396.jpg\n",
      "3 ../resized/rr-0003-0004-12014-272-396.jpg\n",
      "4 ../resized/rr-0004-0004-12014-272-396.jpg\n",
      "1 ../resized/rr-0001-0005-11645-130-56.jpg\n",
      "2 ../resized/rr-0002-0005-11645-130-56.jpg\n",
      "3 ../resized/rr-0003-0005-11645-130-56.jpg\n",
      "4 ../resized/rr-0004-0005-11645-130-56.jpg\n",
      "1 ../resized/rr-0001-0004-1-92-0092.jpg\n",
      "2 ../resized/rr-0002-0004-1-92-0092.jpg\n",
      "3 ../resized/rr-0003-0004-1-92-0092.jpg\n",
      "4 ../resized/rr-0004-0004-1-92-0092.jpg\n",
      "1 ../resized/rr-0001-0003-1-128-0128.jpg\n",
      "2 ../resized/rr-0002-0003-1-128-0128.jpg\n",
      "3 ../resized/rr-0003-0003-1-128-0128.jpg\n",
      "4 ../resized/rr-0004-0003-1-128-0128.jpg\n",
      "1 ../resized/rr-0001-0003-1-92-0092.jpg\n",
      "2 ../resized/rr-0002-0003-1-92-0092.jpg\n",
      "3 ../resized/rr-0003-0003-1-92-0092.jpg\n",
      "4 ../resized/rr-0004-0003-1-92-0092.jpg\n",
      "1 ../resized/rr-0001-0006-11645-126-133.jpg\n",
      "2 ../resized/rr-0002-0006-11645-126-133.jpg\n",
      "3 ../resized/rr-0003-0006-11645-126-133.jpg\n",
      "4 ../resized/rr-0004-0006-11645-126-133.jpg\n",
      "1 ../resized/rr-0001-0006-11645-134-120.jpg\n",
      "2 ../resized/rr-0002-0006-11645-134-120.jpg\n",
      "3 ../resized/rr-0003-0006-11645-134-120.jpg\n",
      "4 ../resized/rr-0004-0006-11645-134-120.jpg\n",
      "1 ../resized/rr-0001-0002-12013-251-409.jpg\n",
      "2 ../resized/rr-0002-0002-12013-251-409.jpg\n",
      "3 ../resized/rr-0003-0002-12013-251-409.jpg\n",
      "4 ../resized/rr-0004-0002-12013-251-409.jpg\n",
      "1 ../resized/rr-0001-0006-11645-126-177.jpg\n",
      "2 ../resized/rr-0002-0006-11645-126-177.jpg\n",
      "3 ../resized/rr-0003-0006-11645-126-177.jpg\n",
      "4 ../resized/rr-0004-0006-11645-126-177.jpg\n",
      "1 ../resized/rr-0001-0001-11645-134-120.jpg\n",
      "2 ../resized/rr-0002-0001-11645-134-120.jpg\n",
      "3 ../resized/rr-0003-0001-11645-134-120.jpg\n",
      "4 ../resized/rr-0004-0001-11645-134-120.jpg\n",
      "1 ../resized/rr-0001-0004-1-187-0187.jpg\n",
      "2 ../resized/rr-0002-0004-1-187-0187.jpg\n",
      "3 ../resized/rr-0003-0004-1-187-0187.jpg\n",
      "4 ../resized/rr-0004-0004-1-187-0187.jpg\n",
      "1 ../resized/rr-0001-0005-1-119-0119.jpg\n",
      "2 ../resized/rr-0002-0005-1-119-0119.jpg\n",
      "3 ../resized/rr-0003-0005-1-119-0119.jpg\n",
      "4 ../resized/rr-0004-0005-1-119-0119.jpg\n",
      "1 ../resized/rr-0001-0001-12382-467-143.jpg\n",
      "2 ../resized/rr-0002-0001-12382-467-143.jpg\n",
      "3 ../resized/rr-0003-0001-12382-467-143.jpg\n",
      "4 ../resized/rr-0004-0001-12382-467-143.jpg\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 ../resized/rr-0001-0006-1-62-0062.jpg\n",
      "2 ../resized/rr-0002-0006-1-62-0062.jpg\n",
      "3 ../resized/rr-0003-0006-1-62-0062.jpg\n",
      "4 ../resized/rr-0004-0006-1-62-0062.jpg\n",
      "1 ../resized/rr-0001-0006-11645-124-69.jpg\n",
      "2 ../resized/rr-0002-0006-11645-124-69.jpg\n",
      "3 ../resized/rr-0003-0006-11645-124-69.jpg\n",
      "4 ../resized/rr-0004-0006-11645-124-69.jpg\n",
      "1 ../resized/rr-0001-0001-11645-126-111.jpg\n",
      "2 ../resized/rr-0002-0001-11645-126-111.jpg\n",
      "3 ../resized/rr-0003-0001-11645-126-111.jpg\n",
      "4 ../resized/rr-0004-0001-11645-126-111.jpg\n",
      "1 ../resized/rr-0001-0001-1-62-0062.jpg\n",
      "2 ../resized/rr-0002-0001-1-62-0062.jpg\n",
      "3 ../resized/rr-0003-0001-1-62-0062.jpg\n",
      "4 ../resized/rr-0004-0001-1-62-0062.jpg\n",
      "1 ../resized/rr-0001-0001-11646-140-81.jpg\n",
      "2 ../resized/rr-0002-0001-11646-140-81.jpg\n",
      "3 ../resized/rr-0003-0001-11646-140-81.jpg\n",
      "4 ../resized/rr-0004-0001-11646-140-81.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0004-11446-46-112.jpg\n",
      "1 ../resized/rr-0001-0004-11446-46-112.jpg\n",
      "../resized/rr-0002-0004-11446-46-112.jpg\n",
      "2 ../resized/rr-0002-0004-11446-46-112.jpg\n",
      "../resized/rr-0003-0004-11446-46-112.jpg\n",
      "3 ../resized/rr-0003-0004-11446-46-112.jpg\n",
      "../resized/rr-0004-0004-11446-46-112.jpg\n",
      "4 ../resized/rr-0004-0004-11446-46-112.jpg\n",
      "1 ../resized/rr-0001-0006-1-92-0092.jpg\n",
      "2 ../resized/rr-0002-0006-1-92-0092.jpg\n",
      "3 ../resized/rr-0003-0006-1-92-0092.jpg\n",
      "4 ../resized/rr-0004-0006-1-92-0092.jpg\n",
      "1 ../resized/rr-0001-0005-11645-117-69.jpg\n",
      "2 ../resized/rr-0002-0005-11645-117-69.jpg\n",
      "3 ../resized/rr-0003-0005-11645-117-69.jpg\n",
      "4 ../resized/rr-0004-0005-11645-117-69.jpg\n",
      "1 ../resized/rr-0001-0004-1-119-0119.jpg\n",
      "2 ../resized/rr-0002-0004-1-119-0119.jpg\n",
      "3 ../resized/rr-0003-0004-1-119-0119.jpg\n",
      "4 ../resized/rr-0004-0004-1-119-0119.jpg\n",
      "1 ../resized/rr-0001-0006-11645-133-90.jpg\n",
      "2 ../resized/rr-0002-0006-11645-133-90.jpg\n",
      "3 ../resized/rr-0003-0006-11645-133-90.jpg\n",
      "4 ../resized/rr-0004-0006-11645-133-90.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0004-11446-49-112.jpg\n",
      "1 ../resized/rr-0001-0004-11446-49-112.jpg\n",
      "../resized/rr-0002-0004-11446-49-112.jpg\n",
      "2 ../resized/rr-0002-0004-11446-49-112.jpg\n",
      "../resized/rr-0003-0004-11446-49-112.jpg\n",
      "3 ../resized/rr-0003-0004-11446-49-112.jpg\n",
      "../resized/rr-0004-0004-11446-49-112.jpg\n",
      "4 ../resized/rr-0004-0004-11446-49-112.jpg\n",
      "1 ../resized/rr-0001-0002-11647-166-51.jpg\n",
      "2 ../resized/rr-0002-0002-11647-166-51.jpg\n",
      "3 ../resized/rr-0003-0002-11647-166-51.jpg\n",
      "4 ../resized/rr-0004-0002-11647-166-51.jpg\n",
      "1 ../resized/rr-0001-0005-1-25-0025.jpg\n",
      "2 ../resized/rr-0002-0005-1-25-0025.jpg\n",
      "3 ../resized/rr-0003-0005-1-25-0025.jpg\n",
      "4 ../resized/rr-0004-0005-1-25-0025.jpg\n",
      "1 ../resized/rr-0001-0002-2-39-0039.jpg\n",
      "2 ../resized/rr-0002-0002-2-39-0039.jpg\n",
      "3 ../resized/rr-0003-0002-2-39-0039.jpg\n",
      "4 ../resized/rr-0004-0002-2-39-0039.jpg\n",
      "1 ../resized/rr-0001-0001-1-187-0187.jpg\n",
      "2 ../resized/rr-0002-0001-1-187-0187.jpg\n",
      "3 ../resized/rr-0003-0001-1-187-0187.jpg\n",
      "4 ../resized/rr-0004-0001-1-187-0187.jpg\n",
      "1 ../resized/rr-0001-0002-1-131-0131.jpg\n",
      "2 ../resized/rr-0002-0002-1-131-0131.jpg\n",
      "3 ../resized/rr-0003-0002-1-131-0131.jpg\n",
      "4 ../resized/rr-0004-0002-1-131-0131.jpg\n",
      "1 ../resized/rr-0001-0002-1-62-0062.jpg\n",
      "2 ../resized/rr-0002-0002-1-62-0062.jpg\n",
      "3 ../resized/rr-0003-0002-1-62-0062.jpg\n",
      "4 ../resized/rr-0004-0002-1-62-0062.jpg\n",
      "1 ../resized/rr-0001-0001-12402-531-78.jpg\n",
      "2 ../resized/rr-0002-0001-12402-531-78.jpg\n",
      "3 ../resized/rr-0003-0001-12402-531-78.jpg\n",
      "4 ../resized/rr-0004-0001-12402-531-78.jpg\n",
      "1 ../resized/rr-0001-0001-1-118-0118.jpg\n",
      "2 ../resized/rr-0002-0001-1-118-0118.jpg\n",
      "3 ../resized/rr-0003-0001-1-118-0118.jpg\n",
      "4 ../resized/rr-0004-0001-1-118-0118.jpg\n",
      "1 ../resized/rr-0001-0004-1-62-0062.jpg\n",
      "2 ../resized/rr-0002-0004-1-62-0062.jpg\n",
      "3 ../resized/rr-0003-0004-1-62-0062.jpg\n",
      "4 ../resized/rr-0004-0004-1-62-0062.jpg\n",
      "1 ../resized/rr-0001-0003-1-169-0169.jpg\n",
      "2 ../resized/rr-0002-0003-1-169-0169.jpg\n",
      "3 ../resized/rr-0003-0003-1-169-0169.jpg\n",
      "4 ../resized/rr-0004-0003-1-169-0169.jpg\n",
      "1 ../resized/rr-0001-0003-1-131-0131.jpg\n",
      "2 ../resized/rr-0002-0003-1-131-0131.jpg\n",
      "3 ../resized/rr-0003-0003-1-131-0131.jpg\n",
      "4 ../resized/rr-0004-0003-1-131-0131.jpg\n",
      "1 ../resized/rr-0001-0001-12403-536-88.jpg\n",
      "2 ../resized/rr-0002-0001-12403-536-88.jpg\n",
      "3 ../resized/rr-0003-0001-12403-536-88.jpg\n",
      "4 ../resized/rr-0004-0001-12403-536-88.jpg\n",
      "1 ../resized/rr-0001-0002-11645-117-69.jpg\n",
      "2 ../resized/rr-0002-0002-11645-117-69.jpg\n",
      "3 ../resized/rr-0003-0002-11645-117-69.jpg\n",
      "4 ../resized/rr-0004-0002-11645-117-69.jpg\n",
      "1 ../resized/rr-0001-0006-12402-532-81.jpg\n",
      "2 ../resized/rr-0002-0006-12402-532-81.jpg\n",
      "3 ../resized/rr-0003-0006-12402-532-81.jpg\n",
      "4 ../resized/rr-0004-0006-12402-532-81.jpg\n",
      "1 ../resized/rr-0001-0006-12384-483-145.jpg\n",
      "2 ../resized/rr-0002-0006-12384-483-145.jpg\n",
      "3 ../resized/rr-0003-0006-12384-483-145.jpg\n",
      "4 ../resized/rr-0004-0006-12384-483-145.jpg\n",
      "1 ../resized/rr-0001-0001-12014-253-337.jpg\n",
      "2 ../resized/rr-0002-0001-12014-253-337.jpg\n",
      "3 ../resized/rr-0003-0001-12014-253-337.jpg\n",
      "4 ../resized/rr-0004-0001-12014-253-337.jpg\n",
      "1 ../resized/rr-0001-0003-11645-124-69.jpg\n",
      "2 ../resized/rr-0002-0003-11645-124-69.jpg\n",
      "3 ../resized/rr-0003-0003-11645-124-69.jpg\n",
      "4 ../resized/rr-0004-0003-11645-124-69.jpg\n",
      "1 ../resized/rr-0001-0001-12013-252-304.jpg\n",
      "2 ../resized/rr-0002-0001-12013-252-304.jpg\n",
      "3 ../resized/rr-0003-0001-12013-252-304.jpg\n",
      "4 ../resized/rr-0004-0001-12013-252-304.jpg\n",
      "1 ../resized/rr-0001-0004-2-39-0039.jpg\n",
      "2 ../resized/rr-0002-0004-2-39-0039.jpg\n",
      "3 ../resized/rr-0003-0004-2-39-0039.jpg\n",
      "4 ../resized/rr-0004-0004-2-39-0039.jpg\n",
      "1 ../resized/rr-0001-0004-11645-126-133.jpg\n",
      "2 ../resized/rr-0002-0004-11645-126-133.jpg\n",
      "3 ../resized/rr-0003-0004-11645-126-133.jpg\n",
      "4 ../resized/rr-0004-0004-11645-126-133.jpg\n",
      "1 ../resized/rr-0001-0001-12409-544-102.jpg\n",
      "2 ../resized/rr-0002-0001-12409-544-102.jpg\n",
      "3 ../resized/rr-0003-0001-12409-544-102.jpg\n",
      "4 ../resized/rr-0004-0001-12409-544-102.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0003-11444-28-95.jpg\n",
      "1 ../resized/rr-0001-0003-11444-28-95.jpg\n",
      "../resized/rr-0002-0003-11444-28-95.jpg\n",
      "2 ../resized/rr-0002-0003-11444-28-95.jpg\n",
      "../resized/rr-0003-0003-11444-28-95.jpg\n",
      "3 ../resized/rr-0003-0003-11444-28-95.jpg\n",
      "../resized/rr-0004-0003-11444-28-95.jpg\n",
      "4 ../resized/rr-0004-0003-11444-28-95.jpg\n",
      "1 ../resized/rr-0001-0001-12402-532-81.jpg\n",
      "2 ../resized/rr-0002-0001-12402-532-81.jpg\n",
      "3 ../resized/rr-0003-0001-12402-532-81.jpg\n",
      "4 ../resized/rr-0004-0001-12402-532-81.jpg\n",
      "1 ../resized/rr-0001-0002-12409-544-102.jpg\n",
      "2 ../resized/rr-0002-0002-12409-544-102.jpg\n",
      "3 ../resized/rr-0003-0002-12409-544-102.jpg\n",
      "4 ../resized/rr-0004-0002-12409-544-102.jpg\n",
      "1 ../resized/rr-0001-0004-12402-532-81.jpg\n",
      "2 ../resized/rr-0002-0004-12402-532-81.jpg\n",
      "3 ../resized/rr-0003-0004-12402-532-81.jpg\n",
      "4 ../resized/rr-0004-0004-12402-532-81.jpg\n",
      "1 ../resized/rr-0001-0004-1-118-0118.jpg\n",
      "2 ../resized/rr-0002-0004-1-118-0118.jpg\n",
      "3 ../resized/rr-0003-0004-1-118-0118.jpg\n",
      "4 ../resized/rr-0004-0004-1-118-0118.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0004-11447-82-145.jpg\n",
      "1 ../resized/rr-0001-0004-11447-82-145.jpg\n",
      "../resized/rr-0002-0004-11447-82-145.jpg\n",
      "2 ../resized/rr-0002-0004-11447-82-145.jpg\n",
      "../resized/rr-0003-0004-11447-82-145.jpg\n",
      "3 ../resized/rr-0003-0004-11447-82-145.jpg\n",
      "../resized/rr-0004-0004-11447-82-145.jpg\n",
      "4 ../resized/rr-0004-0004-11447-82-145.jpg\n",
      "1 ../resized/rr-0001-0001-12013-251-409.jpg\n",
      "2 ../resized/rr-0002-0001-12013-251-409.jpg\n",
      "3 ../resized/rr-0003-0001-12013-251-409.jpg\n",
      "4 ../resized/rr-0004-0001-12013-251-409.jpg\n",
      "1 ../resized/rr-0001-0004-11647-156-201.jpg\n",
      "2 ../resized/rr-0002-0004-11647-156-201.jpg\n",
      "3 ../resized/rr-0003-0004-11647-156-201.jpg\n",
      "4 ../resized/rr-0004-0004-11647-156-201.jpg\n",
      "1 ../resized/rr-0001-0002-12402-532-81.jpg\n",
      "2 ../resized/rr-0002-0002-12402-532-81.jpg\n",
      "3 ../resized/rr-0003-0002-12402-532-81.jpg\n",
      "4 ../resized/rr-0004-0002-12402-532-81.jpg\n",
      "1 ../resized/rr-0001-0004-11646-140-81.jpg\n",
      "2 ../resized/rr-0002-0004-11646-140-81.jpg\n",
      "3 ../resized/rr-0003-0004-11646-140-81.jpg\n",
      "4 ../resized/rr-0004-0004-11646-140-81.jpg\n",
      "1 ../resized/rr-0001-0005-12402-531-78.jpg\n",
      "2 ../resized/rr-0002-0005-12402-531-78.jpg\n",
      "3 ../resized/rr-0003-0005-12402-531-78.jpg\n",
      "4 ../resized/rr-0004-0005-12402-531-78.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0004-11447-81-188.jpg\n",
      "1 ../resized/rr-0001-0004-11447-81-188.jpg\n",
      "../resized/rr-0002-0004-11447-81-188.jpg\n",
      "2 ../resized/rr-0002-0004-11447-81-188.jpg\n",
      "../resized/rr-0003-0004-11447-81-188.jpg\n",
      "3 ../resized/rr-0003-0004-11447-81-188.jpg\n",
      "../resized/rr-0004-0004-11447-81-188.jpg\n",
      "4 ../resized/rr-0004-0004-11447-81-188.jpg\n",
      "1 ../resized/rr-0001-0004-11645-130-56.jpg\n",
      "2 ../resized/rr-0002-0004-11645-130-56.jpg\n",
      "3 ../resized/rr-0003-0004-11645-130-56.jpg\n",
      "4 ../resized/rr-0004-0004-11645-130-56.jpg\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 ../resized/rr-0001-0002-1-92-0092.jpg\n",
      "2 ../resized/rr-0002-0002-1-92-0092.jpg\n",
      "3 ../resized/rr-0003-0002-1-92-0092.jpg\n",
      "4 ../resized/rr-0004-0002-1-92-0092.jpg\n",
      "1 ../resized/rr-0001-0002-1-119-0119.jpg\n",
      "2 ../resized/rr-0002-0002-1-119-0119.jpg\n",
      "3 ../resized/rr-0003-0002-1-119-0119.jpg\n",
      "4 ../resized/rr-0004-0002-1-119-0119.jpg\n",
      "1 ../resized/rr-0001-0002-1-118-0118.jpg\n",
      "2 ../resized/rr-0002-0002-1-118-0118.jpg\n",
      "3 ../resized/rr-0003-0002-1-118-0118.jpg\n",
      "4 ../resized/rr-0004-0002-1-118-0118.jpg\n",
      "1 ../resized/rr-0001-0005-1-128-0128.jpg\n",
      "2 ../resized/rr-0002-0005-1-128-0128.jpg\n",
      "3 ../resized/rr-0003-0005-1-128-0128.jpg\n",
      "4 ../resized/rr-0004-0005-1-128-0128.jpg\n",
      "1 ../resized/rr-0001-0002-11647-156-201.jpg\n",
      "2 ../resized/rr-0002-0002-11647-156-201.jpg\n",
      "3 ../resized/rr-0003-0002-11647-156-201.jpg\n",
      "4 ../resized/rr-0004-0002-11647-156-201.jpg\n",
      "1 ../resized/rr-0001-0002-12014-272-396.jpg\n",
      "2 ../resized/rr-0002-0002-12014-272-396.jpg\n",
      "3 ../resized/rr-0003-0002-12014-272-396.jpg\n",
      "4 ../resized/rr-0004-0002-12014-272-396.jpg\n",
      "1 ../resized/rr-0001-0003-11645-117-69.jpg\n",
      "2 ../resized/rr-0002-0003-11645-117-69.jpg\n",
      "3 ../resized/rr-0003-0003-11645-117-69.jpg\n",
      "4 ../resized/rr-0004-0003-11645-117-69.jpg\n",
      "1 ../resized/rr-0001-0002-1-10-0010.jpg\n",
      "2 ../resized/rr-0002-0002-1-10-0010.jpg\n",
      "3 ../resized/rr-0003-0002-1-10-0010.jpg\n",
      "4 ../resized/rr-0004-0002-1-10-0010.jpg\n",
      "1 ../resized/rr-0001-0006-1-119-0119.jpg\n",
      "2 ../resized/rr-0002-0006-1-119-0119.jpg\n",
      "3 ../resized/rr-0003-0006-1-119-0119.jpg\n",
      "4 ../resized/rr-0004-0006-1-119-0119.jpg\n",
      "1 ../resized/rr-0001-0003-11645-126-133.jpg\n",
      "2 ../resized/rr-0002-0003-11645-126-133.jpg\n",
      "3 ../resized/rr-0003-0003-11645-126-133.jpg\n",
      "4 ../resized/rr-0004-0003-11645-126-133.jpg\n",
      "1 ../resized/rr-0001-0004-1-131-0131.jpg\n",
      "2 ../resized/rr-0002-0004-1-131-0131.jpg\n",
      "3 ../resized/rr-0003-0004-1-131-0131.jpg\n",
      "4 ../resized/rr-0004-0004-1-131-0131.jpg\n",
      "1 ../resized/rr-0001-0003-11645-133-90.jpg\n",
      "2 ../resized/rr-0002-0003-11645-133-90.jpg\n",
      "3 ../resized/rr-0003-0003-11645-133-90.jpg\n",
      "4 ../resized/rr-0004-0003-11645-133-90.jpg\n",
      "1 ../resized/rr-0001-0006-1-25-0025.jpg\n",
      "2 ../resized/rr-0002-0006-1-25-0025.jpg\n",
      "3 ../resized/rr-0003-0006-1-25-0025.jpg\n",
      "4 ../resized/rr-0004-0006-1-25-0025.jpg\n",
      "1 ../resized/rr-0001-0001-1-25-0025.jpg\n",
      "2 ../resized/rr-0002-0001-1-25-0025.jpg\n",
      "3 ../resized/rr-0003-0001-1-25-0025.jpg\n",
      "4 ../resized/rr-0004-0001-1-25-0025.jpg\n",
      "1 ../resized/rr-0001-0005-1-118-0118.jpg\n",
      "2 ../resized/rr-0002-0005-1-118-0118.jpg\n",
      "3 ../resized/rr-0003-0005-1-118-0118.jpg\n",
      "4 ../resized/rr-0004-0005-1-118-0118.jpg\n",
      "1 ../resized/rr-0001-0005-12013-251-409.jpg\n",
      "2 ../resized/rr-0002-0005-12013-251-409.jpg\n",
      "3 ../resized/rr-0003-0005-12013-251-409.jpg\n",
      "4 ../resized/rr-0004-0005-12013-251-409.jpg\n",
      "1 ../resized/rr-0001-0003-1-187-0187.jpg\n",
      "2 ../resized/rr-0002-0003-1-187-0187.jpg\n",
      "3 ../resized/rr-0003-0003-1-187-0187.jpg\n",
      "4 ../resized/rr-0004-0003-1-187-0187.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0003-11446-44-84.jpg\n",
      "1 ../resized/rr-0001-0003-11446-44-84.jpg\n",
      "../resized/rr-0002-0003-11446-44-84.jpg\n",
      "2 ../resized/rr-0002-0003-11446-44-84.jpg\n",
      "../resized/rr-0003-0003-11446-44-84.jpg\n",
      "3 ../resized/rr-0003-0003-11446-44-84.jpg\n",
      "../resized/rr-0004-0003-11446-44-84.jpg\n",
      "4 ../resized/rr-0004-0003-11446-44-84.jpg\n",
      "1 ../resized/rr-0001-0001-12384-483-145.jpg\n",
      "2 ../resized/rr-0002-0001-12384-483-145.jpg\n",
      "3 ../resized/rr-0003-0001-12384-483-145.jpg\n",
      "4 ../resized/rr-0004-0001-12384-483-145.jpg\n",
      "1 ../resized/rr-0001-0002-12014-253-337.jpg\n",
      "2 ../resized/rr-0002-0002-12014-253-337.jpg\n",
      "3 ../resized/rr-0003-0002-12014-253-337.jpg\n",
      "4 ../resized/rr-0004-0002-12014-253-337.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0003-11447-81-94.jpg\n",
      "1 ../resized/rr-0001-0003-11447-81-94.jpg\n",
      "../resized/rr-0002-0003-11447-81-94.jpg\n",
      "2 ../resized/rr-0002-0003-11447-81-94.jpg\n",
      "../resized/rr-0003-0003-11447-81-94.jpg\n",
      "3 ../resized/rr-0003-0003-11447-81-94.jpg\n",
      "../resized/rr-0004-0003-11447-81-94.jpg\n",
      "4 ../resized/rr-0004-0003-11447-81-94.jpg\n",
      "[(0, 453), (453, 906)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0002-11447-82-145.jpg\n",
      "1 ../resized/rr-0001-0002-11447-82-145.jpg\n",
      "../resized/rr-0002-0002-11447-82-145.jpg\n",
      "2 ../resized/rr-0002-0002-11447-82-145.jpg\n",
      "../resized/rr-0003-0002-11447-82-145.jpg\n",
      "3 ../resized/rr-0003-0002-11447-82-145.jpg\n",
      "../resized/rr-0004-0002-11447-82-145.jpg\n",
      "4 ../resized/rr-0004-0002-11447-82-145.jpg\n",
      "1 ../resized/rr-0001-0001-1-10-0010.jpg\n",
      "2 ../resized/rr-0002-0001-1-10-0010.jpg\n",
      "3 ../resized/rr-0003-0001-1-10-0010.jpg\n",
      "4 ../resized/rr-0004-0001-1-10-0010.jpg\n",
      "1 ../resized/rr-0001-0006-12011-232-242.jpg\n",
      "2 ../resized/rr-0002-0006-12011-232-242.jpg\n",
      "3 ../resized/rr-0003-0006-12011-232-242.jpg\n",
      "4 ../resized/rr-0004-0006-12011-232-242.jpg\n",
      "[(0, 453), (453, 907)] [(0, 382), (382, 765)]\n",
      "../resized/rr-0001-0005-11447-81-94.jpg\n",
      "1 ../resized/rr-0001-0005-11447-81-94.jpg\n",
      "../resized/rr-0002-0005-11447-81-94.jpg\n",
      "2 ../resized/rr-0002-0005-11447-81-94.jpg\n",
      "../resized/rr-0003-0005-11447-81-94.jpg\n",
      "3 ../resized/rr-0003-0005-11447-81-94.jpg\n",
      "../resized/rr-0004-0005-11447-81-94.jpg\n",
      "4 ../resized/rr-0004-0005-11447-81-94.jpg\n",
      "1 ../resized/rr-0001-0005-12014-253-337.jpg\n",
      "2 ../resized/rr-0002-0005-12014-253-337.jpg\n",
      "3 ../resized/rr-0003-0005-12014-253-337.jpg\n",
      "4 ../resized/rr-0004-0005-12014-253-337.jpg\n",
      "1 ../resized/rr-0001-0006-11645-126-111.jpg\n",
      "2 ../resized/rr-0002-0006-11645-126-111.jpg\n",
      "3 ../resized/rr-0003-0006-11645-126-111.jpg\n",
      "4 ../resized/rr-0004-0006-11645-126-111.jpg\n",
      "1 ../resized/rr-0001-0003-12402-531-78.jpg\n",
      "2 ../resized/rr-0002-0003-12402-531-78.jpg\n",
      "3 ../resized/rr-0003-0003-12402-531-78.jpg\n",
      "4 ../resized/rr-0004-0003-12402-531-78.jpg\n",
      "1 ../resized/rr-0001-0004-11645-126-177.jpg\n",
      "2 ../resized/rr-0002-0004-11645-126-177.jpg\n",
      "3 ../resized/rr-0003-0004-11645-126-177.jpg\n",
      "4 ../resized/rr-0004-0004-11645-126-177.jpg\n",
      "1 ../resized/rr-0001-0003-1-25-0025.jpg\n",
      "2 ../resized/rr-0002-0003-1-25-0025.jpg\n",
      "3 ../resized/rr-0003-0003-1-25-0025.jpg\n",
      "4 ../resized/rr-0004-0003-1-25-0025.jpg\n",
      "1 ../resized/rr-0001-0004-1-10-0010.jpg\n",
      "2 ../resized/rr-0002-0004-1-10-0010.jpg\n",
      "3 ../resized/rr-0003-0004-1-10-0010.jpg\n",
      "4 ../resized/rr-0004-0004-1-10-0010.jpg\n",
      "1 ../resized/rr-0001-0003-1-49-0049.jpg\n",
      "2 ../resized/rr-0002-0003-1-49-0049.jpg\n",
      "3 ../resized/rr-0003-0003-1-49-0049.jpg\n",
      "4 ../resized/rr-0004-0003-1-49-0049.jpg\n",
      "1 ../resized/rr-0001-0003-1-119-0119.jpg\n",
      "2 ../resized/rr-0002-0003-1-119-0119.jpg\n",
      "3 ../resized/rr-0003-0003-1-119-0119.jpg\n",
      "4 ../resized/rr-0004-0003-1-119-0119.jpg\n",
      "1 ../resized/rr-0001-0002-1-187-0187.jpg\n",
      "2 ../resized/rr-0002-0002-1-187-0187.jpg\n",
      "3 ../resized/rr-0003-0002-1-187-0187.jpg\n",
      "4 ../resized/rr-0004-0002-1-187-0187.jpg\n",
      "1 ../resized/rr-0001-0002-12384-483-145.jpg\n",
      "2 ../resized/rr-0002-0002-12384-483-145.jpg\n",
      "3 ../resized/rr-0003-0002-12384-483-145.jpg\n",
      "4 ../resized/rr-0004-0002-12384-483-145.jpg\n"
     ]
    }
   ],
   "source": [
    "for images in all_images:\n",
    "    image = cv.imread(images)\n",
    "    height = image.shape[0]\n",
    "    width = image.shape[1]\n",
    "    if height > width:\n",
    "        h_list = list(np.linspace(0, image.shape[0], 3, dtype=\"int32\"))\n",
    "        w_list = list(np.linspace(0,image.shape[1], 3, dtype=\"int32\"))\n",
    "        pairs_h = [(h_list[0], h_list[1]),(h_list[1], h_list[2])]\n",
    "        pairs_w = [(w_list[0], w_list[1]),(w_list[1], w_list[2])]\n",
    "        print(pairs_h,pairs_w)\n",
    "\n",
    "        index = 0\n",
    "        for h in pairs_h:\n",
    "            for w in pairs_w:\n",
    "                cropped_image = image[h[0]:h[1],w[0]:w[1]]\n",
    "                index=index+1\n",
    "                filename = os.path.join(\"../resized\",\"rr-\"+str(index).zfill(4)+\"-\"+images)\n",
    "                print(filename)\n",
    "                #cv.imwrite(filename,cropped_image)\n",
    "                print(index,filename)\n",
    "    elif height < width:\n",
    "        h_list = list(np.linspace(0, image.shape[0], 3, dtype=\"int32\"))\n",
    "        w_list = list(np.linspace(0,image.shape[1],3,dtype=\"int32\"))\n",
    "        pairs_h = [(h_list[0], h_list[1]),(h_list[1], h_list[2])]\n",
    "        pairs_w = [(w_list[0], w_list[1]),(w_list[1], w_list[2])]\n",
    "\n",
    "        index = 0\n",
    "        for h in pairs_h:\n",
    "            for w in pairs_w:\n",
    "                cropped_image = image[h[0]:h[1],w[0]:w[1]]\n",
    "                index = index+1\n",
    "                filename = os.path.join(\"../resized\",\"rr-\"+str(index).zfill(4)+\"-\"+images)\n",
    "                #cv.imwrite(filename, cropped_image)\n",
    "                print(index, filename)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SPLIT - TRAIN AND TEST SETS`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "255"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.chdir(\"/home/kiprono/Documents/STELLENBOSCH UNIVERISTY/\\\n",
    "Masters by Research/Mask RCNN/Annotation projects/RRR/resized\")\n",
    "\n",
    "resized = os.listdir(os.getcwd())\n",
    "train = random.sample(resized,int(0.75*len(resized)))\n",
    "len(train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "for image in train:\n",
    "    source = image\n",
    "    dest = os.path.join(\"../train_images\",image)\n",
    "    #shutil.move(source,dest)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
